package org.uniview.common.service;

import junit.framework.TestCase;

/**
 * Describe service abstract test case.
 * 
 * @author James Gao
 * @version 1.0 2007-1-28
 */
public abstract class ServiceTestCase extends TestCase {

	/**
	 * Application context file, which is in file system path or classpath.
	 */
	protected String contextFilePath;

	/**
	 * Server name.
	 */
	protected String serverName;

	/**
	 * Service lifecycle.
	 */
	private ServiceLifecycleMain serviceLifecycle;

	public ServiceTestCase() {
		super();
	}

	/**
	 * The subclass must be invoke this constructor.
	 * 
	 * @param contextFilePath
	 *            Application context file, which is in file system path or
	 *            classpath.
	 */
	public ServiceTestCase(String contextFilePath) {
		super();
		this.contextFilePath = contextFilePath;
		this.serverName = serverName;
	}

	/**
	 * The subclass must be invoke this constructor.
	 * 
	 * @param contextFilePath
	 *            Application context file, which is in file system path or
	 *            classpath.
	 * @param serverName
	 *            the server's name.
	 */
	public ServiceTestCase(String contextFilePath, String serverName) {
		super();
		this.contextFilePath = contextFilePath;
		this.serverName = serverName;
	}

	/**
	 * Startup server.
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		if (serverName == null || serverName.trim().equals("")) {
			serviceLifecycle = new ServiceLifecycleMain(contextFilePath);
		} else {
			serviceLifecycle = new ServiceLifecycleMain(contextFilePath, serverName);
		}
		serviceLifecycle.contextDestroyed(null);
	}

	/**
	 * Shutdown server.
	 * 
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		serviceLifecycle.contextDestroyed(null);
	}

}
